package com.gis.config;

import com.gis.handler.BatchFileWebSocketHandler;
import com.gis.handler.WebSocketHandler;
import com.gis.service.ScriptService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
@RequiredArgsConstructor
public class WebSocketConfig implements WebSocketConfigurer {
    private final WebSocketHandler webSocketHandler;
    private final BatchFileWebSocketHandler batchFileWebSocketHandler;
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册 WebSocket 处理器和端点
        registry.addHandler(webSocketHandler, "/ws/task")
                .addHandler(batchFileWebSocketHandler, "/ws/batchFile")
                .setAllowedOrigins("*");  // 允许跨域
    }
}
